package edu.uis.csc478.spring09.threeoxen.application.usermgmt;

import edu.uis.csc478.spring09.threeoxen.application.BaseDialog;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class UserManagementApplication extends BaseDialog implements ActionListener {
    private JPanel contentPane;
    private JButton addNewUserButton;
    private JButton modifyExistingUserButton;
    private JButton displayUserListButton;
    private JButton exitButton;

    public UserManagementApplication() {
        setContentPane(contentPane);
        setModal(true);
        addNewUserButton.addActionListener(this);
        modifyExistingUserButton.addActionListener(this);
        displayUserListButton.addActionListener(this);
        exitButton.addActionListener(this);
    }

    public static void main(String[] args) {
        UserManagementApplication dialog = new UserManagementApplication();
        dialog.pack();
        dialog.setVisible(true);
        System.exit(0);
    }

    @Override
    public void actionPerformed(ActionEvent e) {

        if (e.getSource().equals(this.exitButton)) {
            System.exit(0);
            dispose();
        }

        JDialog dialog = null;
        String newDialogClassName = null;
        if (e.getSource().equals(this.addNewUserButton)) {
            newDialogClassName = "edu.uis.csc478.spring09.threeoxen.application.usermgmt.AddNewUser";
        }
        if (e.getSource().equals(this.modifyExistingUserButton)) {
            newDialogClassName = "edu.uis.csc478.spring09.threeoxen.application.usermgmt.ModifyUser";
            showMessageDialog((Component) e.getSource(), "This feature is not implemented yet");
            return;
        }
        if (e.getSource().equals(this.displayUserListButton)) {
            newDialogClassName = "edu.uis.csc478.spring09.threeoxen.application.usermgmt.DisplayUsers";
            showMessageDialog((Component) e.getSource(), "This feature is not implemented yet");
            return;
        }
        try {
            dialog = createNewDialog(newDialogClassName, true);
        } catch (Exception ex) {
            showMessageDialog((Component) e.getSource(), "Error creating new dialog.");
            ex.printStackTrace();
        }
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /** Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        contentPane = new JPanel();
        contentPane.setLayout(new GridBagLayout());
        contentPane.setMinimumSize(new Dimension(170, 115));
        contentPane.setPreferredSize(new Dimension(170, 115));
        contentPane.setBorder(BorderFactory.createTitledBorder("User Management Application"));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
        GridBagConstraints gbc;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        contentPane.add(panel1, gbc);
        addNewUserButton = new JButton();
        addNewUserButton.setText("Add New User");
        panel1.add(addNewUserButton, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        modifyExistingUserButton = new JButton();
        modifyExistingUserButton.setText("Modify Existing User");
        panel1.add(modifyExistingUserButton, new com.intellij.uiDesigner.core.GridConstraints(1, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        displayUserListButton = new JButton();
        displayUserListButton.setText("Display User List");
        panel1.add(displayUserListButton, new com.intellij.uiDesigner.core.GridConstraints(2, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        exitButton = new JButton();
        exitButton.setText("Exit");
        panel1.add(exitButton, new com.intellij.uiDesigner.core.GridConstraints(3, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    }

    /** @noinspection ALL */
    public JComponent $$$getRootComponent$$$() {
        return contentPane;
    }
}
